<?php 
$total_time = 0;
$tot = 0;
$present_days =0;
?>
<div class="row-fluid">

<div class="span9">
<h3><?php echo $this->ion_auth->get_username($this->uri->segment(4))?> attendance sheet for month of  <?php

 echo $monthName = date("F", mktime(0, 0, 0, $this->uri->segment(6), 10));
 
 ?></h3>
 
<table class="table table-striped table-hover table-condensed" width="100%">	
		<tr class="text-info">
			<td>Date</td>
			<td>Entry Time</td>
			<td>Exit Time</td>
			<td>Total Working Hours</td>
			<td>Action</td>
			
		</tr>	
	<tbody>
	<?php 
	
	foreach($daily_sheets as $daily_sheet){?>
	<?php for($i=1;$i<=$num;$i++){
		
		if($i<10)
		{
		$day = 'day_0'.$i;	
		$date_id = '0'.$i;
		}
	else{
		$day = 'day_'.$i;
		$date_id = $i;
		}
		?>
		
	<tr <?php if($daily_sheet->$day=='sunday'){?> class="text-error error" <?php }?> >
		<td><?php echo date("F", mktime(0, 0, 0, $this->uri->segment(6), 10)).' '.$date_id?></td>
		<td>
		<?php 		
		$time_details = $this->attendance_model->get_time($user_id,$daily_sheet->year_id,$daily_sheet->month_id,$date_id);
		if(!empty($time_details['entry_time'])){
		echo DATE("g:i a", STRTOTIME($time_details['entry_time']));
		}	
		?>
		</td>
		<td><?php 
		if(!empty($time_details['exit_time'])){
		echo DATE("g:i a", STRTOTIME($time_details['exit_time']));}?></td>
		<td><?php echo $daily_sheet->$day;		
		// explode the time
		if(isset($daily_sheet->$day) && !empty($daily_sheet->$day) && $daily_sheet->$day!='sunday'){
		$present_days +=1 ;		
		$time_explode = explode(':',$daily_sheet->$day);
		 $tot_hr = $time_explode[0]*60*60;
		 $tot_min = $time_explode[1]*60;
		 $tot = $tot_hr + $tot_min;
		 $total_time += $tot;
		}
		?></td>	
		<td><a href="<?php echo site_url('founder/attendance/delete_attendance').'/'.$time_details['id']?>"><i class="icon-trash"></i></a></td>	
	</tr>
	<?php }}?>	
	</tbody>
</table>

</div>
<div class="span3">
<a href="<?= site_url('user/attendance/edit_attendance')?>">Edit Attendance</a>
<header>Monthly Status</header>
<b>No. of Working Days   : </b>25 days<br />
<b>Average Working Hr   : </b><?php 

if(isset($min_working_hr['min_working_hour'])){
echo $min_working_hr['min_working_hour'].'hrs';	
}else{
	echo '<a href="'.site_url("founder/salary").'">No Salary has been defined</a>';
}


?> 
<hr />
<b>Present : </b> <?php echo $present_days?> days<br/>
<b>Total Working Hr      : </b>  <?php 
$hours = floor($total_time / 3600);
$minutes = floor(($total_time / 60) % 60);
echo $sumtime = $hours .':'.$minutes;
?> hrs<br />

<?php 

?>
<b>Average :</b>  <?php 
if($present_days > 0){	
$avg_time = $total_time / $present_days;
$hr = floor($avg_time / 3600);
$min = floor(($avg_time / 60) % 60);
echo $hr.':'.$min;	
}else{
	echo '0';	
}

?> 

<header>Attendance Sheet</header>
<ul>
<?php foreach($attendance as $attend){?>
<li><a href="<?php echo site_url('founder/attendance/index').'/'.$attend->user_id.'/'.$attend->year_id.'/'.$attend->month_id?>"><?php echo date("F",mktime(0, 0, 0,$attend->month_id, 10));?></a></li>
<?php }?>
</ul>
<br /><br />

<header>Salary Status</header>
<table width="100%">
<tr>
<td width="40%">My Salary</td>
<td width="60%">: Rs. 0</td>
</tr>
<tr>
<td>Deducted Salary</td>
<td>: Rs. 0</td>
</tr>
<tr>
<td>Payable Salary</td>
<td>: Rs. 0</td>
</tr>
</table>
<br />
<br />

<header>Leave Status</header>

<table width="100%">
  <tr>
    <td width="40%">Paid Leave Available</td>
    <td width="60%">: 1</td>
  </tr>
  <tr>
    <td>Leave Taken</td>
    <td>: 2</td>
  </tr>
  <tr>
    <td>Absent</td>
    <td>: 4</td>
  </tr>
</table>

</div>
</div>